<?php
	session_start();
	
	if(isset($_GET["board"]))
	{
		$post_board = $_GET["board"];
	}
	
//取文件夹中的所有表情
function getsmiles() {
  if ($handle = opendir('images/smiles')) {
    while (false !== ($file = readdir($handle))) {
      if (preg_match('/(.+?)[.]gif/ie',$file, $name)) {
        $result[$name[1]]=$file;
      }
    }
    closedir($handle);
    return $result;
  }else{
    return;
  }
}
// 评论表情
function displaysmiley($smile) {
  $smile=htmlspecialchars($smile);
  if(is_file('images/smiles/'.$smile.'.gif')) {
    $img='<img src="./images/smiles/'.$smile.'.gif" >';
  }
  return $img;
}

?>
<html>
<head>
<title>新帖发布</title>
<meta charset = "utf-8" />
<link rel = "stylesheet" href = "public.css" style = "text/css" >
<script type = "text/javascript" src = "jquery-1.7.1.js"></script>
<script>
	$(function(){
		$("#new_title").focus();
	});
</script>
<script>
function $(id) {
	return document.getElementById(id);
}
function insertsmiley(icon) {  
  $('new_content').value+= ':'+icon+':';
  $('new_content').focus();
}
</script>


<script>
	function check_public(form)
	{
		if(form.new_title.value==""){
			alert("请输入标题");
			form.new_title.focus();
			return(false);
		}

		if(form.new_content.value==""){
			alert("请输入文章内容");
			form.new_content.focus();
			return(false);
		}

		
		return(true);

	}


</script>
</head>
<body>
<div class = "header">
<p>小树林BBS--新帖发布页</p>
</div>

<div class = "content" >
	
	<div class = "side_bar">
		<ul>	
			<li><a href = "page.php?board=<?php if(isset($_GET["board"])){ echo $post_board; } ?>" id = "post_index">返回版面</a></li>
			<li><a href = "#" id = "post_all">主帖一览</a></li>
			<li><a href = "public.php" id = "post_add">发布新帖</a></li>
			<li><a href = "#" id = "post_edit">修改帖子</a></li>
			<li><a href = "#" id = "post_delete">删除帖子</a></li>
			<li><a href = "#" id = "post_save">收藏帖子</a></li>
		</ul>
	</div>


	
	<div class = "public_news">
		<table>
			<form action = "public_process.php" method= "post" class = "new_post_form" id = "new_post_form" name = "new_post_form" onsubmit="return check_public(new_post_form)" >
				<tr>
					<input type = "hidden" name = "hide_board_name" value = "<?php echo $post_board; //此条提交接受后可知道发布在哪个版面 ?>" id = "hide_board_name" />
					<td>帖子标题</td>
					<td><pre><input type = "text" name ="new_title" id = "new_title" /></pre></td>
				</tr>
				
				 <tr>	
						<td>添加表情</td>
						<td>
						<?php 
							$smiles=getsmiles();
							foreach($smiles as $key => $value){
								echo "<img src=\"images/smiles/".$value."\" style=\"cursor:pointer\" onclick=\"insertsmiley('".$key."')\"/> ";
							}
							unset($smiles);
						?>
						</td>
				 </tr>

				<tr>
					<td><label for = "new_content">帖子内容</label></td>
					<td><pre><textarea rows = "10" cols = "30" name = "new_content" id = "new_content"/></textarea></pre></td>
				</tr>

				<tr>
					<td></td>
					<td>
						<input type = "submit" value = "发布" name = "submit_news" id = "submit_news" onclick="check_public(new_post_form)" />
						<input type = "reset" value = "重新输入" name = "reset_news" id = "reset_news" />
					</td>
				</tr>
			
			</form>
		</table>
	</div>
	



</div>

<div class = "footer" >

</div>

</body>

</html>